#include <gtest/gtest.h>
#include <numeric>
#include <vector>

#include "dumpParser.h"

TEST(dumpParser, getFuncStart)
{
    DumpParser dumpParser("unknown");
    string asmLine("0000000000010620 <main>:");
    string funcName;
    bool res = dumpParser.getFuncStart(asmLine, funcName);
    EXPECT_EQ(res, true);
    EXPECT_EQ(funcName, "main");
}

TEST(dumpParser, getFuncCall1)
{
    DumpParser dumpParser("unknown");
    string asmLine("    f014:	ff d0                	call   *%rax");
    string funcName;
    bool res = dumpParser.getFuncCall(asmLine, funcName);
    EXPECT_EQ(res, false);
}
TEST(dumpParser, getFuncCall2)
{
    DumpParser dumpParser("unknown");
    string asmLine("    fc65:	e8 96 70 00 00       	call   16d00 <_ZN5clipp14parsing_resultD1Ev>");
    string funcName;
    bool res = dumpParser.getFuncCall(asmLine, funcName);
    EXPECT_EQ(res, true);
    EXPECT_EQ(funcName, "_ZN5clipp14parsing_resultD1Ev");
}
TEST(dumpParser, getFuncCall3)
{
    DumpParser dumpParser("unknown");
    string asmLine("    facf:	e8 0c ff ff ff       	call   f9e0 <_Unwind_Resume@plt>");
    string funcName;
    bool res = dumpParser.getFuncCall(asmLine, funcName);
    EXPECT_EQ(res, true);
    EXPECT_EQ(funcName, "_Unwind_Resume@plt");
}
TEST(dumpParser, getFuncCall4)
{
    DumpParser dumpParser("unknown");
    string asmLine("je     11dfc <main+0x17ec>");
    string funcName;
    bool res = dumpParser.getFuncCall(asmLine, funcName);
    EXPECT_EQ(res, true);
    EXPECT_EQ(funcName, "main");
}
int main(int argc, char *argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}